<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
The Box Model
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot074.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot076.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc185">14.1</A>&nbsp;&nbsp;The Box Model</H2><UL>
<LI><A HREF="umsroot075.html#toc112">Breakpoints</A>
</UL>

<A NAME="boxmodel"></A>
The ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> debugger is based on a port model which is an extension
of the classical Box Model commonly used in Prolog debugging.<BR>
<BR>
A procedure invocation (or goal) is represented by a box with entry
and exit ports. Each time a procedure is invoked, a box is created
and given a unique invocation number. The invocations of subgoals of
this procedure are seen as boxes inside this procedure box.
<BLOCKQUOTE CLASS="figure"><DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV>
<DIV CLASS="center">
<IMG SRC="umsroot009.gif">
</DIV>
<BR>
<BR>
<DIV CLASS="center">Figure 14.1: The box model</DIV><BR>
<BR>

<DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>
Tracing the flow of the execution consists in tracing the crossing of
the execution flow through any of the port of the box.<BR>
<BR>
The five basic ports of the box model of ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> are the CALL, EXIT,
REDO, FAIL and NEXT ports, the suspension facilities are traced through
the DELAY and RESUME ports, and the exceptional exit is indicated by LEAVE.
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description"><B>CALL:</B><DD CLASS="dd-description"> When a procedure is invoked, the flow of the execution
enters the procedure box by its CALL port and enters the first clause
box which could (since not all clauses are tried, some of them being
sure to fail, i.e. indexing is shown) unify with the goal.
It may happen that a procedure is
called with arguments that make it sure to fail (because of
indexing). In such cases, the flow does not enter any clause box.<BR>
<BR>
For each CALL port a new procedure box is created and is given:
<UL CLASS="itemize"><LI CLASS="li-itemize">
an <I>invocation number</I> that is one higher than that given for
the most recent CALL port. This allows to uniquely identify a
procedure invocation and all its corresponding ports.<BR>
<BR>
<LI CLASS="li-itemize">a <I>level</I> that is one higher than that of its parent goal.
</UL><BR>
The displayed variable instantiations are the ones at call time,
i.e. before the head unification of any clause.<BR>
<BR>
<DT CLASS="dt-description"><B>EXIT:</B><DD CLASS="dd-description"> When a clause of a predicate succeeds (i.e. unification
succeeded and all procedures called by the clause succeeded),
the flow gets out of the box by the EXIT port of both boxes (only
the EXIT port of the <I>procedure box</I> is traced).<BR>
<BR>
When a procedure exits non-deterministically (and there are still
other clauses to try on that procedure or one of its children goals
has alternatives which could be resatisfied), the EXIT port is traced
with an asterisk (*EXIT). When the last possibly matching clause of a
procedure is exited, the exit is traced without asterisk. This means
that this procedure box will never be retried as there is no other
untried alternative.<BR>
<BR>
The instantiations shown in the EXIT port are the ones at exit time,
they result from the (successful) execution of the procedure.<BR>
<BR>
<DT CLASS="dt-description"><B>FAIL:</B><DD CLASS="dd-description"> When a clause of a procedure fails (because head unification
failed or because a sub-goal failed), the flow of the execution exits
the clause box and leaves the procedure box via the FAIL port.
Note that the debugger cannot display any argument information at
FAIL ports (an ellipsis <CODE>...</CODE> is displayed instead for each argument).<BR>
<BR>
<DT CLASS="dt-description"><B>NEXT:</B><DD CLASS="dd-description"> If a clause fails and there is another possibly
matching clause to try, then that one is tried for unification.
The flow of the execution from the failure of one clause to the
head unification of a following clause is traced as a NEXT port.
The displayed variable instantiations are the same as those of the
corresponding CALL or REDO port.<BR>
<BR>
<DT CLASS="dt-description"><B>ELSE:</B><DD CLASS="dd-description">
This is similar to the NEXT port, but indicates that the next branch of a
<A HREF="../bips/kernel/control/O-2.html"><B>disjunction (;/2)</B></A><A NAME="@default751"></A>
it tried after the previous branch failed.
The predicate that gets displayed with the port is the predicate
which contains the disjunction (the immediate ancestor).<BR>
<BR>
<DT CLASS="dt-description"><B>REDO:</B><DD CLASS="dd-description"> When a procedure box is exited trough an *EXIT port,
the box can be retried later to get a new solution. This will happen when a
later goal fails. The backtracking will cause failing of all
procedures that do not have any alternative, then the execution flow
will enter a
procedure box that an contains alternative through a REDO port.<BR>
<BR>
Two situations may occur: either the last tried clause has called a
procedure that has left a choice point (it has exited through an
*EXIT port). In that case the nested procedure box is re-entered
though another REDO-port.<BR>
<BR>
Otherwise, if the last clause tried does not contain any
nondeterministically exited boxes, but there are other untried clauses
in the procedure box, the next possibly matching clause will be tried.<BR>
<BR>
The last REDO port in such a sequence is the one which contains the
actual alternative that is tried. The variable instantiations for all
REDO ports in such a sequence are the ones corresponding to the call
time of the last one.<BR>
<BR>
<DT CLASS="dt-description"><B>LEAVE:</B><DD CLASS="dd-description">
This port allows to trace the execution of a the
<A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default752"></A> and
<A HREF="../bips/kernel/control/exit_block-1.html"><B>exit_block/1</B></A><A NAME="@default753"></A>
predicates within the box model. The predicate
<A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default754"></A> is traced as
a normal procedure. If the goal in its first argument fails,
<A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default755"></A> fails, if it
exits, <A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default756"></A> exits. 
If the predicate <A HREF="../bips/kernel/control/exit_block-1.html"><B>exit_block/1</B></A><A NAME="@default757"></A> is called (and exited since it
never fails), all the goals inside the matching block are left through
a special port called LEAVE, so that each entry port matches with an
exit port. The recover procedure (in the third argument of
<A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default758"></A>) is then
called and traced normally and
<A HREF="../bips/kernel/control/block-3.html"><B>block/3</B></A><A NAME="@default759"></A> will exit or
fail (or even leave) depending on the recover procedure.<BR>
<BR>
As with the FAIL port, no argument value are displayed in the LEAVE port.<BR>
<BR>
<DT CLASS="dt-description"><B>DELAY:</B><DD CLASS="dd-description">
The displayed goal becomes suspended. This is a singleton port, it does
not enter or leave a box. However, a new <I>invocation number</I> is assigned
to the delayed goal, and this number will be used in the matching RESUME port.
The DELAY port is caused by one of the built-in predicates
<A HREF="../bips/kernel/suspensions/suspend-3.html"><B>suspend/3</B></A><A NAME="@default760"></A>,
<A HREF="../bips/kernel/suspensions/suspend-4.html"><B>suspend/4</B></A><A NAME="@default761"></A>,
<A HREF="../bips/kernel/suspensions/make_suspension-3.html"><B>make_suspension/3</B></A><A NAME="@default762"></A>
or a delay clause.
The port is displayed just after the delayed goal has been created.<BR>
<BR>
<DT CLASS="dt-description"><B>RESUME:</B><DD CLASS="dd-description"> When a waking condition causes the resuming of
a delayed goal, the procedure box is entered through its RESUME
port. The box then behaves as if it had been entered through its CALL
port. The invocation number is the same as in its previous DELAY port.
which makes it easy to identify corresponding delay and resume events.
However the depth level of the RESUME corresponds to the waking situation.
It is traced like a subgoal of the goal which has caused the waking.</DL>
In the rest of this chapter the user interface to the debugger is
described, including the commands available in the debugger itself as
well as built-in predicates which influence it. Some of the debugger
commands are explained using an excerpt of a debugger session. In
these examples, the user input is always underlined (it is in fact
not always output as typed) to distinguish it from the computer output.<BR>
<BR>
<A NAME="toc112"></A>
<H3 CLASS="subsection"><A NAME="htoc186">14.1.1</A>&nbsp;&nbsp;Breakpoints</H3>
Breakpoints can be set on specific calls to a predicate, i.e. on a specific
body goal in the source, so that the
debugger will stop only at a CALL port only when that specific body goal is 
executed. A breakpoint is specify by giving the source file and the line
number where the body goal is. <BR>
<BR>
For example, if the following predicate is in a file called <CODE>newtop</CODE>,
with the following line numbers:
<PRE CLASS="verbatim">
  243  check_words([],[]).
  244  check_words([Word|Words],[RevWord|RevWords]) :-
  245     check_words(Words,RevWords).
</PRE>
The breakpoint for the body goal verb'check_words(Words,RevWords)' would be
<CODE>newtop:245</CODE>. Note that the file name must be sufficiently specified 
for ECLiPSe to find the file from your current working directory.<BR>
<BR>
For a call that has a breakpoint set, the execution will stop when the call
is made, i.e. at the CALL port for that specific body goal.<BR>
<BR>
<HR>
<A HREF="umsroot074.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot076.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
